﻿using MyCode.Project.Domain.Message.Request.Activity;
using MyCode.Project.Domain.Message.Request.Clerk;
using MyCode.Project.Domain.Message.Response.Activity;
using MyCode.Project.Domain.Message.Response.CardCover;
using MyCode.Project.Domain.Message.Response.Member;
using MyCode.Project.Domain.Message.Response.Shop;
using MyCode.Project.Domain.Message.Response.User;
using MyCode.Project.Infrastructure.Common;
using MyCode.Project.Infrastructure.Exceptions;
using MyCode.Project.Services;
using System;
using System.Collections.Generic;
using System.Web.Http;

namespace MyCode.Project.WebApi.Areas.Wechat.Controllers
{
    /// <summary>
    ///营销中心  相关
    /// </summary>
    public class ActivityController : BaseWechatController
    {
        private IActivityService _activityService;
        private IMemberInfoService _memberInfoService;

        /// <summary>
        /// 初始化一个<see cref="ActivityController"/>类型的实例
        /// </summary>
        public ActivityController(IActivityService activityService
            , IMemberInfoService memberInfoService)
        {
            _activityService = activityService;
            _memberInfoService = memberInfoService;
        }

        #region 加盟商、店长或店员获取店铺活动列表
        /// <summary>
        /// 加盟商、店长或店员获取店铺活动列表
        /// </summary>
        /// <param name="ShopID">店铺ID(店长或店员可不传参)</param>
        [HttpGet]
        public ActivityResp GetActivityList(Guid? ShopID)
        {
            ShopID = ShopID.HasValue ? ShopID : this.CurrentLogin.ShopId;
            if (!ShopID.HasValue)
            {
                throw new LoginError("登录信息已失效,请重新登录");
            }
            return _activityService.GetActivityList(ShopID.Value, this.CurrentLogin);
        }
        #endregion

        #region (加盟商、店长或店员端)活动详情
        /// <summary>
        /// (加盟商、店长或店员端)活动详情
        /// </summary>
        /// <param name="shopId">店铺ID（加盟商角色且店铺已参加活动时需传）</param>
        /// <param name="ID">活动主键ID</param>
        [HttpGet]
        public ActivityDetail GetDetail(Guid? shopId,Guid ID)
        {
            shopId = shopId.HasValue ? shopId.Value : this.CurrentLogin.ShopId;
            return _activityService.GetDetail(shopId.Value,ID,this.CurrentLogin);
        }
        #endregion

        #region (加盟商、店长或店员端)通用活动/分销活动/报名活动--详情
        /// <summary>
        /// (加盟商、店长或店员端)通用活动/分销活动--详情
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        public ActivityCommonDetail GetCommonDetail(CommonActivityReq request)
        {
            request.shopId = request.shopId.HasValue ? request.shopId.Value : this.CurrentLogin.ShopId.Value;
            return _activityService.GetCommonDetail(request, this.CurrentLogin);
        }
        #endregion

        #region 通用活动/报名活动详情--(加盟商已存在奖品池信息) 加盟商修改奖品池 
        /// <summary>
        ///  通用活动/报名活动 详情--(加盟商已存在奖品池信息) 加盟商修改奖品池 
        /// </summary>
        /// <param name="itemId">奖品明细ID</param>
        /// <param name="isChoosed">是否选中 0：取消选中  1：选中</param>
        [HttpGet]
        public void SetCommonPrize(Guid itemId,int isChoosed)
        {
            _activityService.SetCommonPrize(itemId, isChoosed, this.CurrentLogin);
        }
        #endregion

        #region 马上参加
        /// <summary>
        /// 马上参加
        /// </summary>
        /// <param name="VoucherID">代金券ID 活动二可不传</param>
        /// <param name="ActivityID">活动主键ID</param>
        /// <param name="IsAll">是否所有店铺参与该活动 0：否  1：是</param>
        /// <param name="ShopID">选择只有当前店铺参与活动   当前店铺ID</param>
        public void SetShopJoin(Guid? VoucherID, Guid ActivityID, int IsAll, Guid? ShopID)
        {
            _activityService.SetShopJoin(VoucherID, ActivityID, IsAll,ShopID,this.CurrentLogin);
        }
        #endregion

        #region 活动三-马上参加
        /// <summary>
        /// 活动三-马上参加
        /// </summary>
        [HttpPost]
        public void SetOnlyShopJoin(ShopJoinReq request)
        {
            request.ShopID = request.ShopID.HasValue ? request.ShopID : this.CurrentLogin.ShopId;
            _activityService.SetOnlyShopJoin(request,this.CurrentLogin);
        }
        #endregion

        #region 通用活动/报名活动-马上参加
        /// <summary>
        /// 通用活动/报名活动-马上参加
        /// </summary>
        [HttpPost]
        public void SetAllShopJoin(AllShopJoinReq request)
        {
            _activityService.SetAllShopJoin(request, this.CurrentLogin);
        }
        #endregion

        #region 分销活动-马上参加
        /// <summary>
        /// 分销活动-马上参加
        /// </summary>
        [HttpPost]
        public void SetIsAllShopJoin(IsAllShopJoinReq request)
        {
            _activityService.SetIsAllShopJoin(request, this.CurrentLogin);
        }
        #endregion

        #region 活动数据统计
        /// <summary>
        /// 活动数据统计
        /// </summary>
        [HttpPost]
        public DataCenterResp GetDataStatistics(DataCenterReq request)
        {
            request.ShopID = request.ShopID.HasValue ? request.ShopID : this.CurrentLogin.ShopId;
            return _activityService.GetDataStatistics(request, this.CurrentLogin);
        }
        #endregion

        //#region GetShopShareCode(加盟商/店员分享活动小程序海报)
        ///// <summary>
        ///// 加盟商/店员分享活动小程序海报,返回完整的图片URL
        ///// </summary>
        ///// <param name="shopActivityId"></param>     
        ///// <returns></returns>
        //[HttpGet]
        //public string GetCustomerShareCode(Guid shopActivityId)
        //{
        //    return _activityService.GetCustomerShareCode(shopActivityId,CurrentLogin);
        //}
        //#endregion

        #region 修改代金券
        /// <summary>
        /// 修改代金券
        /// </summary>
        /// <param name="logId">店铺参与活动记录ID</param>
        /// <param name="voucherId">代金券ID</param>
        [HttpGet]
        public void SetShopVoucher(Guid logId, Guid voucherId)
        {
            _activityService.SetShopVoucher(logId, voucherId, this.CurrentLogin);
        }
        #endregion

        #region 修改兑换方案
        /// <summary>
        /// 修改兑换方案
        /// </summary>
        /// <param name="logId">店铺参与活动记录ID</param>
        /// <param name="caseId">兑换方案主键ID</param>
        [HttpGet]
        public void SetShopCase(Guid logId, Guid caseId)
        {
            _activityService.SetShopCase(logId, caseId, this.CurrentLogin);
        }
        #endregion

        #region 溯源数据
        /// <summary>
        /// 溯源数据
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        [HttpPost]
        public PageResult<OriginResp> GetOriginPageList(PagedSearch<OriginReq> search)
        {
            return _activityService.GetOriginPageList(search,this.CurrentLogin);
        }
        #endregion

        #region 报名活动-溯源数据查看报名信息
        /// <summary>
        /// 报名活动-溯源数据查看报名信息
        /// </summary>
        /// <param name="Id">溯源信息主键Id</param>
        /// <returns></returns>
        [HttpGet]
        public ApplyInfo GetApplyInfo(Guid Id)
        {
            return _activityService.GetApplyInfo(Id);
        }
        #endregion

        #region 加盟商取消参与活动
        /// <summary>
        /// 加盟商取消参与活动
        /// </summary>
        /// <param name="id">活动主键ID</param>
        /// <param name="shopId">店铺主键ID</param>
        [HttpGet]
        public void CancelJoinActivity(Guid id,Guid shopId)
        {
            _activityService.CancelJoinActivity(id,shopId,this.CurrentLogin);
        }
        #endregion

        #region 调度开启活动
        /// <summary>
        /// 调度开启活动
        /// </summary>
        [HttpGet]
        [AllowAnonymous]
        public void ActivityBegin()
        {
            _activityService.JoinProcessToActivity();
        }
        #endregion

        #region 管理层-进行中活动列表
        /// <summary>
        /// 管理层-进行中活动列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<ActivityListResp> GetInActivityList()
        {
            return _activityService.GetActivityList();
        }
        #endregion

        #region 管理层-所有非禁用与非进行中的活动列表
        /// <summary>
        /// 管理层-所有非禁用与非进行中的活动列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<ActivityListResp> GetAllActivityList()
        {
            return _activityService.GetAllActivityList();
        }
        #endregion

        #region 强提醒-每天未核销人数
        /// <summary>
        /// 强提醒-每天未核销人数
        /// </summary>
        /// <param name="shopId">加盟商角色必传</param>
        /// <returns></returns>
        public List<UnusedList> GetUnusedList(Guid? shopId)
        {
            shopId = shopId.HasValue ? shopId : this.CurrentLogin.ShopId;
            return _activityService.GetUnusedList(shopId,this.CurrentLogin);
        }
        #endregion

        #region 首页轮播图
        /// <summary>
        /// 首页轮播图
        /// </summary>
        /// <param name="shopID">店铺ID</param>
        /// <returns></returns>
        [HttpGet]
        public List<HomePageResp> GetHomePageList(Guid? shopID)
        {
            return _activityService.GetHomePageList(shopID, 1);
        }
        #endregion

        #region GetCustomPage 获取自定义页面信息
        /// <summary>
        /// 获取自定义页面信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public CustomPage GetCustomPage(Guid id)
        {
            return _memberInfoService.GetCustomPage(id);
        }
        #endregion

        #region GetCustomerSharePic(门店端获取拼接海报的多个图片)
        /// <summary>
        /// 门店端获取拼接海报的多个图片
        /// </summary>
        /// <param name="shopActivityId"></param>      
        /// <returns></returns>
        [HttpGet]
        public CustomerSharePicResp GetCustomerSharePic(Guid shopActivityId)
        {
            return _activityService.GetCustomerSharePicNew(shopActivityId, CurrentLogin,true);
        }
        #endregion


        #region GetMiniCodeUrl(获取1280小程序码)
        /// <summary>
        /// 获取1280小程序码
        /// </summary>
        /// <param name="shopActivityId"></param>       
        /// <returns></returns>
        [HttpGet]
        public string Get1280MiniCodeUrl(Guid shopActivityId)
        {
            return _activityService.Get1280MiniCodeUrl(shopActivityId, CurrentLogin, true);
        }
        #endregion


        #region ClearActivityCache(清除已经结束的活动的缓存内容)
        /// <summary>
        /// 清除已经结束的活动的缓存内容
        /// </summary>
        [HttpGet]
        [AllowAnonymous]
        public void ClearActivityCache()
        {
            _activityService.ClearActivityCache();
        }
        #endregion



        #region ResetKeyExpire(刷新店员添加客户的小程序码的redis有效期)
        /// <summary>
        /// 刷新店员添加客户的小程序码的redis有效期
        /// </summary>
        [HttpGet]
        [AllowAnonymous]
        public void ResetKeyExpire()
        {
            _activityService.ResetKeyExpire();
        }
        #endregion
    }
}

